package com.jjb.www.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.hjq.shape.layout.ShapeRelativeLayout;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.UserRecordApi;
import com.jjb.www.ui.activity.GraduationActivity;
import com.umeng.commonsdk.debug.E;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class EvaluationAdapter extends AppAdapter<UserRecordApi.Bean.ArrDTO.MyArrDTO> {

    public EvaluationAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private ShapeTextView mTvName;
        private ShapeTextView mTvTime;
        private ShapeImageView mImgType;
        private ShapeTextView mTvBranch;
        private ShapeRelativeLayout mRlItem;



        private ViewHolder() {
            super(R.layout.item_education2);
            mTvName = findViewById(R.id.tv_name);
            mTvTime = findViewById(R.id.tv_time);
            mImgType = findViewById(R.id.img_type);
            mTvBranch = findViewById(R.id.tv_branch);
            mRlItem = findViewById(R.id.rl_item);
        }

        @Override
        public void onBindView(int position) {
            mTvName.setText(getItem(position).getName());
            mTvTime.setText(getItem(position).getTime());
            if ("".equals(getItem(position).getFraction())){
                mTvBranch.setVisibility(View.GONE);
                mImgType.setVisibility(View.VISIBLE);
            }else {
                mTvBranch.setVisibility(View.VISIBLE);
                mImgType.setVisibility(View.GONE);
                try {
                    int fraction = Integer.parseInt(getItem(position).getFraction());
                    mTvBranch.setText(fraction+"分");
                }catch (Exception e){
                    mTvBranch.setText(getItem(position).getFraction());
                }

            }
            if ("".equals(getItem(position).getFraction())){
                mRlItem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.putExtra("id",getItem(position).getId()+"");
                        intent.setClass(getContext(), GraduationActivity.class);
                        getContext().startActivity(intent);
                    }
                });
            }
        }
    }
}